const { DataTypes } = require('sequelize');
const sequelize = require('@shared/utils/database');

const OrderItem = sequelize.define('OrderItem', {
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true,
    comment: '订单商品ID'
  },
  order_id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    comment: '订单ID'
  },
  product_id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    comment: '商品ID'
  },
  product_snapshot: {
    type: DataTypes.JSON,
    allowNull: false,
    comment: '商品快照'
  },
  quantity: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '购买数量'
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '商品单价'
  },
  total_amount: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '商品总价'
  }
}, {
  tableName: 'order_item',
  timestamps: true,
  createdAt: 'create_time',
  updatedAt: false
});

module.exports = OrderItem; 